<?php
class Box_Matrix_edit extends BoxEdit
{
	protected function EditBox( $box, $edit_param )
	{
		$this->SetTemplate(  "box:Matrix/BoxMatrixEdit",
							I18N("Setup matrix..."),
							I18N("Save matrix") );

		$cols = $box->Get("cols");
		$rows = $box->Get("rows");
		$cells = array();
		for ( $r = 0; $r < $rows; $r++ )
		{
			$row = array();
			for ( $c = 0; $c < $cols; $c++ )
				$row[$c] = $box->GetChild( "-R-$r-C-$c" );
			$cells[ $r ] = $row;
		}
		return array(
					"cols" => $cols,
					"rows" => $rows,
					"items" => $cells
					);
	}
	protected function SaveBox( $box, $edit_param )
	{
		$old_rows = $box->Get("rows");
		$old_cols = $box->Get("cols");

		$rows = Core::PostVar("rows_return",$old_rows , "int");
		$cols = Core::PostVar("cols_return", $old_cols, "int");
		$matrix = Core::PostVar("matrix_return", false, "serialized");
		# Remove any additional child
		for ( $r = $rows; $r < $old_rows; $r++ )
			for ( $c = $cols; $c < $old_cols; $c++ )
				$box->RemoveChild("-R-$r-C-$c");

		$box->Set("rows", $rows) && $this->SetReload(true);
		$box->Set("cols", $cols) && $this->SetReload(true);

/*
cambia: qui lista
		for ( $r = 0; $r < $rows; $r++ )
			for ( $c = 0; $c < $cols; $c++ )
				if ( isset( $matrix["r".$r."c".$c ] ) )
					$box->SetChild( "-R-$r-C-$c", $matrix["r".$r."c".$c ] ) && $this->SetReload(true);*/

		echo I18N("Matrix saved: NO DA IMPLEMENTARE");
	}
}
?>